package S_Algorithm;

import java.util.ArrayList;
import java.util.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author DannyYo
 */
public class CSCAN {
	public int m=0;	//用来存放磁头的初始位置
        
         List list = new ArrayList();
	public int b[]=new int[101];
        
	public boolean Run=true;
	public double sum=0;
	public void Check(int aa[],int n,int position,Object[] o){
		int temp;
                int a[]=aa.clone();
		for (int i = n; i > 0; i--) // 冒泡排序
		{
			for (int j = 0; j < i; j++) {
				if (a[j] > a[j + 1]) // 按顺序依次比较大小
				{
					temp = a[j]; // 把大的数字往前面放
					a[j] = a[j + 1];
					a[j + 1] = temp;
				}
			}
		}
		
		while (Run) {//此循环用来寻找磁头的初始位置被排到了什么位置
			for (int i = 0; i <= n; i++) {
				if (a[i] == position) {
					m = i;
					Run = false;
				}
			}
		}
		
		System.out.println("CSCAN算法序列：");
		for(int i=m+1;i<=n;i++){//磁头向大号移动
			sum=sum+a[i]-a[i-1];
			System.out.print(a[i]+"   ");
                         list.add(a[i]);
		}
		sum=sum+200-a[n];
		sum=sum+199;
		sum=sum+a[0]-1;
		for(int i=0;i<=m-1;i++){
			if(i!=m-1){
				sum=sum+a[i+1]-a[i];
			}
			System.out.print(a[i]+"   ");
                         list.add(a[i]);
		}
		System.out.println();
		System.out.println("寻道长度为"+sum);
		System.out.println("平均寻道长度为"+sum/n);
                
                    Object[] bb= list.toArray();
                  for(int k=0;k<10;k++){
//                    System.out.println("aaa序列为：");
//                    System.out.print(bb[k] + "     ");
                    b[k+1]=(int)bb[k];
                }
                 o[6]=b;  
                 o[7]=sum;
                 
	}

    

}